var _player;
var _playButton;
var _cursor;
var _cursorStoryboard;
var _cursorAnimation;

function media_opened(sender, args) {
    // cache references
    _player = sender.findName("player");
    _playButton = sender.findName("playButton");

    agControl.style.width = _player.Width = _player.NaturalVideoWidth;
    agControl.style.height = _player.Height = _player.NaturalVideoHeight;

//    _cursor = sender.findName("cursor");
//    _cursorStoryboard = sender.findName("cursorStoryboard");
//    _cursorAnimation = sender.findName("doubleanimation");
//    _cursorAnimation.To = (agControl.style.width.replace("px", "") - _cursor.Width);
//    _cursorAnimation.Duration = _player.NaturalDuration;
//    _cursor.setValue("Canvas.Top", _player.Height - _cursor.Height - 10);
}

function media_ended(sender, args) {
//    _cursorStoryboard.stop();
//    _cursor.setValue("Canvas.Left", 0);

    _player.stop();
    _playButton.Text = "play";
}

function media_playpause(sender, args) {
    if (_playButton.Text == "pause") {

//        _cursorStoryboard.pause();

        _player.pause();
        _playButton.Text = "play";
    } else {

//        if (_player.Position.seconds == 0) _cursorStoryboard.Begin();
//        else _cursorStoryboard.Resume();

        _player.play();
        _playButton.Text = "pause";
    }
}

function canvas_loaded(sender, args) {
    var control = sender.getHost();
    control.FullScreenChanged = "javascript:onFullScreenChanged";
}

function toggle_fullScreen(sender, args) {
    agControl.fullScreen = !agControl.fullScreen;  
}

function onFullScreenChanged(sender, args) {
    _player.width = agControl.actualWidth;
    _player.height = agControl.actualHeight;

//    _cursorAnimation.To = _player.width;
//    _cursor.setValue("Canvas.Top", _player.height - _cursor.height - 10);
//    _cursor.setValue("Canvas.Left", _player.Position / _player.NaturalDuration * _player.width);
}